package cn.hrlly.tao2shou.biz;

import com.zhy.http.okhttp.OkHttpUtils;

import java.io.File;

import cn.hrlly.tao2shou.other.Config;
import cn.hrlly.tao2shou.callback.EditCommodityCallback;
import cn.hrlly.tao2shou.domain.Commodity;
import cn.hrlly.tao2shou.listener.OnEditCommodityListener;

/**
 * User: gengliang
 * Date: 2016-01-28
 * Time: 13:02
 */

public class EditCommodityBizImpl implements EditCommodityBiz {

    private OnEditCommodityListener onEditCommodityListener;

    public EditCommodityBizImpl(OnEditCommodityListener onEditCommodityListener){
        this.onEditCommodityListener=onEditCommodityListener;
    }

    @Override
    public void alterCommodity(Commodity commodity, File[] file) {
        OkHttpUtils
                .post()
                .url(Config.key_url)
                .addFile(Config.key_file, Config.key_commodity_file1, file[0])
                .addFile(Config.key_file,Config.key_commodity_file2,file[1])
                .addFile(Config.key_file,Config.key_commodity_file3,file[2])
                .addParams(Config.key_action,Config.action_alter_commodity)
                .addParams(Config.key_commodity_name, commodity.getCommodityName())
                .addParams(Config.key_commodity_count, String.valueOf(commodity.getCommodityCount()))
                .addParams(Config.key_classification,commodity.getClassification())
                .addParams(Config.key_expected_price, String.valueOf(commodity.getExpectedPrice()))
                .addParams(Config.key_barter_description,commodity.getBarterDescription())
                .addParams(Config.key_new_degree, String.valueOf(commodity.getNewDegree()))
                .addParams(Config.key_commodity_description, commodity.getCommodityDescription())
                .addParams(Config.key_expected_time, commodity.getExpectedTime())
                .addParams(Config.key_expected_location, commodity.getExpectedLocation())
                .addParams(Config.key_release_id,commodity.getReleaseId())
                .build()
                .execute(new EditCommodityCallback(onEditCommodityListener));
    }

    @Override
    public void deleteCommodity(Commodity commodity) {
        OkHttpUtils
                .post()
                .url(Config.key_url)
                .addParams(Config.key_action,Config.action_delete_commodity)
                .addParams(Config.key_release_id,commodity.getReleaseId())
                .build()
                .execute(new EditCommodityCallback(onEditCommodityListener));
    }
}
